package com.aegis.manage.controller.gateway;

import com.aegis.common.mybatis.model.PageResult;
import com.aegis.manage.api.request.*;
import com.aegis.manage.api.vo.ApiPermissionVO;
import com.aegis.manage.api.vo.AuthPermissionTypeVO;
import com.aegis.manage.api.vo.PermissionGroupVO;
import com.aegis.manage.service.auth.app.AuthAppPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/gateway/permissionGroup")
public class GatewayPermissionGroupController {

    @Autowired
    private AuthAppPermissionService authAppPermissionService;


    /**
     * 查询权限组分页
     *
     * @param request
     * @return
     */
    @GetMapping("/page")
    public PageResult<PermissionGroupVO> queryApiPage(@Validated QueryPermissionGroupPageRequest request) {
        return authAppPermissionService.queryPermissionGroupPage(request);
    }

    /**
     * 查询权限组api分页
     *
     * @param request
     * @return
     */
    @GetMapping("/api/page")
    public PageResult<ApiPermissionVO> queryGroupApiPermissionPage(@Validated QueryGroupApiPermissionPageRequest request) {
        return authAppPermissionService.queryGroupApiPermissionPage(request);
    }

    /**
     * 删除权限组绑定的api
     * @param id
     */
    @DeleteMapping("/api/del")
    public void delGroupApi(@RequestParam("id") String id) {
        authAppPermissionService.delGroupApi(id);
    }

    /**
     * 创建权限组
     *
     * @param request
     */
    @PostMapping("/create")
    public void createApi(@RequestBody @Validated AddPermissionGroupRequest request) {
        authAppPermissionService.insertPermissionGroup(request);
    }


    /**
     * 更新权限组
     *
     * @param request
     */
    @PutMapping("/update")
    public void updateApi(@RequestBody @Validated UpdatePermissionGroupRequest request) {
        authAppPermissionService.updatePermissionGroup(request);
    }


    /**
     * 删除权限组
     *
     * @param id
     */
    @DeleteMapping("/del")
    public void delApi(@RequestParam("id") String id) {
        authAppPermissionService.delPermissionGroup(id);
    }

    /**
     * @param request
     */
    @PostMapping("/bindApiPermission")
    public void bindApiPermission(@RequestBody @Validated BindApiPermissionRequest request) {
        authAppPermissionService.bindApiPermission(request);
    }


    /**
     *
     * @return
     */
    @GetMapping("/permissionType/list")
    public List<AuthPermissionTypeVO> queryPermissionType() {
        return authAppPermissionService.queryPermissionType();
    }

}
